// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:

import { GameEvent } from "../../common/scripts/GameEvent";

//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
export enum CardType {
    Card = 0,
    Face = 1,
    Back = 2
}
export enum CardColor {
    fk = "fk",
    h = "h",
    ht = "ht",
    mh = "mh"
}

export  interface CardInfo {
    cardColor: CardColor;
    cardPoint: number;
}

const {ccclass, property} = cc._decorator;

@ccclass
export default class Card extends cc.Component {

    @property(cc.SpriteAtlas)
    cardsSP: cc.SpriteAtlas = null;
    @property(cc.Sprite)
    cardFace: cc.Sprite = null;
    @property(cc.Node)
    cardBack: cc.Node = null;

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}
    
    cardInfo: CardInfo = {
        cardColor: CardColor.fk,
        cardPoint: 1
    }
    start () {

    }

    init(cardColor: any, cardPoint: number){
        this.cardFace.spriteFrame = this.cardsSP.getSpriteFrame(`${cardColor}_${cardPoint}`);
        this.cardInfo.cardColor = cardColor;
        this.cardInfo.cardPoint = cardPoint;
    } 

    open() {
        this.cardBack.active = false;
     
    }

    moveTo() {
        this.node.x = 100;
        this.node.y = 100;
    }

    moveBy() {
        this.node.x += 100;
        this.node.y += 100;
    }

    onClick() {
        cc.game.emit(GameEvent.Crazy8_OnCardClick, this);
    }

    enableCardClickEvent(){
        console.log("enableCardClickEvent");
        this.node.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
    }

    disableCardClickEvent(){
        this.node.off(cc.Node.EventType.TOUCH_END, this.onClick, this);
    }


    // update (dt) {}
}
